﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Routing;
using System.Web.Mvc;
using Web7.Extensions;
using Web7.RouteUrlModifiers;

namespace Web7.Core.Extensions
{
    public static class RouteCollectionExtensions
    {
        public static Route MapRoute(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces, IRouteUrlModifier routeModifier, string appName)
        {
            if (url.StartsWith("/"))
                url = url.Substring(1);
            Route route = routes.MapRoute(name, routeModifier.ModifyUrl(url), defaults, constraints, namespaces);
            if (!appName.IsNullOrWhiteSpace())
                route.DataTokens["AppName"] = appName;
            return route;
        }
    }
}
